package com.haoshuang.zhouzhoubang.ui.page.order.appeal

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.OrderDetailBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class AppealViewModel : BaseViewModel() {

    /**
     * 获取订单详情
     */
    val getServiceOrderDetailData = StatefulMutableLiveData<ResponseBean<OrderDetailBean>>()
    fun getServiceOrderDetail(id: String?) = netRequest {
        start { getServiceOrderDetailData.value = StateData.Loading }
        request { ApiRepo.getServiceOrderDetail(id)  }
        success { getServiceOrderDetailData.value = StateData.Success(it) }
        error { code, msg ->
            getServiceOrderDetailData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 提交申诉
     */
    val appealOrderFeedbackData = StatefulMutableLiveData<ResponseBean<Any>>()
    fun appealOrderFeedback(feedback_id: Int?, content: String, pics: String) = netRequest {
        start { appealOrderFeedbackData.value = StateData.Loading }
        request { ApiRepo.appealOrderFeedback(feedback_id, content, pics)  }
        success { appealOrderFeedbackData.value = StateData.Success(it) }
        error { code, msg ->
            appealOrderFeedbackData.value = StateData.Error(code, msg)
        }
    }

    /**
     * 差评申诉
     */
    val userOrderAppealData = StatefulMutableLiveData<Any>()
    fun userOrderAppeal(orderId: Int?, content: String, images: String) = netRequest {
        start { userOrderAppealData.value = StateData.Loading }
        request { ApiRepo.userOrderAppeal(orderId, content, images)  }
        success { userOrderAppealData.value = StateData.Success(it.data) }
        error { code, msg ->
            userOrderAppealData.value = StateData.Error(code, msg)
        }
    }

}